package com.sgb.auction.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.sgb.auction.BR;
import com.sgb.auction.R;
import com.sgb.auction.entity.AuctionManageListEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import java.util.List;

/**
 * Time:2021/11/22
 * AUTHOR:F_Q
 * Description:
 */
public class AuctionManageAdapter extends BaseRecycleAdapter<AuctionManageListEntity> {

    public AuctionManageAdapter(Context context, List<AuctionManageListEntity> datas) {
        super(context, R.layout.auction_manage_items, datas);
    }

    @Override
    public void onBindViewHolder(ItemViewHolder holder, @SuppressLint("RecyclerView") int position) {
        super.onBindViewHolder(holder, position);
        ImageView pmGlState = holder.itemView.findViewById(R.id.pm_gl_state);
        TextView pmGlTime = holder.itemView.findViewById(R.id.pm_gl_time);
        TextView abortiveauctionwhy = holder.itemView.findViewById(R.id.abortive_auction_why);//流拍原因
        TextView tv_from_pat = holder.itemView.findViewById(R.id.tv_from_pat);//撤拍原因
        TextView from_pat = holder.itemView.findViewById(R.id.from_pat);//撤拍按钮
        TextView from_pat_time = holder.itemView.findViewById(R.id.from_pat_time);//撤拍时间
        LinearLayout llFromPat = holder.itemView.findViewById(R.id.ll_from_pat);//撤拍原因布局
//拍卖状态（0、草稿，1、待拍卖，2、拍卖中，3、拍卖结束4、流拍5、撤拍）
        switch (datas.get(position).getState()){
            case 0://草稿
                break;
            case 1://待拍卖
                pmGlState.setImageResource(R.mipmap.pm_dpm);
                pmGlTime.setText("拍卖开始时间："+datas.get(position).getAuctionStartTime()+"");
                from_pat.setVisibility(View.VISIBLE);
                abortiveauctionwhy.setVisibility(View.GONE);
                llFromPat.setVisibility(View.GONE);
                break;
            case 2://拍卖中
                pmGlState.setImageResource(R.mipmap.pm_pmz);
                pmGlTime.setText("拍卖结束时间："+datas.get(position).getAuctionEndTime()+"");
                from_pat.setVisibility(View.VISIBLE);
                abortiveauctionwhy.setVisibility(View.GONE);
                llFromPat.setVisibility(View.GONE);
                break;
            case 3://拍卖结束
                pmGlState.setImageResource(R.mipmap.pm_pmjs);
                pmGlTime.setText("拍卖结束时间："+datas.get(position).getAuctionEndTime()+"");
                from_pat.setVisibility(View.GONE);
                abortiveauctionwhy.setVisibility(View.GONE);
                llFromPat.setVisibility(View.GONE);
                break;
            case 4://流拍
                pmGlState.setImageResource(R.mipmap.pm_lp);
                pmGlTime.setText("拍卖结束时间："+datas.get(position).getAuctionEndTime()+"");
                from_pat.setVisibility(View.GONE);
                abortiveauctionwhy.setVisibility(View.VISIBLE);
                llFromPat.setVisibility(View.GONE);
                if (datas.get(position).getVersion()>0){
                    abortiveauctionwhy.setText("流拍原因 : 拍卖结束时，最高出价小于保留价");
                }else {
                    abortiveauctionwhy.setText("流拍原因 : 拍卖时间内无人出价");
                }
                break;
            case 5://撤拍
                pmGlState.setImageResource(R.mipmap.pm_cp);
                pmGlTime.setText("拍卖结束时间："+datas.get(position).getAuctionEndTime()+"");
                from_pat.setVisibility(View.GONE);
                abortiveauctionwhy.setVisibility(View.GONE);
                llFromPat.setVisibility(View.VISIBLE);
                tv_from_pat.setText("撤拍原因 : "+datas.get(position).getReason()+"");
                from_pat_time.setText("撤拍时间 : "+datas.get(position).getCancelTime());
                break;
        }
        from_pat.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                OnItemStateOperate.onFromPatData(datas.get(position));
            }
        });
    }

    @Override
    public void convert(ItemViewHolder holder, AuctionManageListEntity entity) {
        holder.setBinding(BR.viewModel, entity);
    }
    private OnItemStateOperate OnItemStateOperate;

    public void setOnItemStateOperate(OnItemStateOperate onItemStateOperate) {
        OnItemStateOperate = onItemStateOperate;
    }

    public interface OnItemStateOperate {

        void onFromPatData(AuctionManageListEntity entity);

    }

}
